let { init, exec, sql, transaction } = require('mysqls')

init({
	host: '123.59.214.207',
	user: 'root',
	password:'rootroot',
	database: 'test',
	port: 3306,
})


const Api = {
	select: async (table, query)=>{
		try{
			return await sql.table(table).where(query).select(true).exec()
		}catch (err){
			console.log(err)
		}
	},
	insert: async (table, query)=>{
		try{
			let sqli = await sql.table(table).data(query).insert(true).exec()
			console.log(sqli)

			return sqli
		}catch (err){
			console.log(err)
		}
	},
	update: async (table, query)=>{
		try{
			let id = query.id
			console.log(query)

			let sqlstr = sql.table(table).data(query).where({id:id}).update()
			return  await exec(sqlstr);
		}catch (err){
			console.log(err)
		}
	},
	delet: async (table, query)=>{
		try{
			let sqlstr = sql.table(table).where(query).delet()
			return  await exec(sqlstr);

		}catch (err){
			console.log(err)
		}
	},
}

module.exports = Api
